#include <threadunit/TestSram.h>
#include "jsonrpc/icore.h"

Icore *TestSram::icore4 = nullptr;

/**
 * @brief thread entry of TestSram, run in dead loop
 * （TestSram的线程入口函数，进行死循环）
 * @param parameter rt_mq_t（消息队列结构体）
 */
void TestSram::TestSram_thread_entry(void *parameter)
{
    icore4->sram->handle((rt_mq_t)parameter);
}

/**
 * @brief constructor of TestSram, and insert method to this->methodNameList
 * （TestSram的构造函数，并在this->methodNameList中插入调用的函数）
 * @param main 
 */
TestSram::TestSram(Icore *main)
{
    fsmc = new FSMC;

    icore4 = main;
    entry = TestSram_thread_entry;
    FunName = "TestSram";
    init("TestSram", 20);

    methodNameList.insert(pair<string, methodPrt>("test", test));
    methodNameList.insert(pair<string, methodPrt>("printCmd", printCmd));
    methodNameList.insert(pair<string, methodPrt>("printParam", printParam));
    methodNameList.insert(pair<string, methodPrt>("printReset", printReset));
}

TestSram::~TestSram()
{
    // TODO 自动生成的析构函数存根
}

void TestSram::test(cJSON *json_params)
{
}

void TestSram::printCmd(cJSON *json_params)
{
    cJSON *num;
    int result;
    num = cJSON_GetObjectItem(json_params, "num");
    icore4->printCmd(num->valueint, &result);
}

void TestSram::printReset(cJSON *json_params)
{
    cJSON *num;
    num = cJSON_GetObjectItem(json_params, "num");
    icore4->printReset(num->valueint);
}

void TestSram::printParam(cJSON *json_params)
{
    cJSON *addr, *data;
    int result;
    addr = cJSON_GetObjectItem(json_params, "addr");
    data = cJSON_GetObjectItem(json_params, "data");
    icore4->printParam(addr->valueint, data->valueint, &result);
}
